{% extends "personal_center/base.html" %}

{% block page_link %}
    <link rel="stylesheet" href="../../static/technological/css/style.css">
    <link rel="stylesheet" href="../../static/public_file/css/PersonnelChooser.css">
{% endblock %}


{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }
        .add_background {
            background: #A9A9A9;
        }
        tr td {
            height: 35px;padding-right: 5px;outline: none;
        }
        th {
            text-align: center;
        }
        .file {
            position: relative;display: inline-block;background: #D0EEFF;border: 1px solid #99D3F5;border-radius: 4px;padding: 4px 12px;overflow: hidden;color: #1E88C7;text-decoration: none;text-indent: 0;line-height: 20px;
        }
        .file input {
            position: absolute;font-size: 100px;right: 0;top: 0;opacity: 0;
        }
        .file:hover {
            background: #AADFFD;border-color: #78C3F3;color: #004974;text-decoration: none;
        }
        #ThreeNavigation div {
            padding-left: 2%;
        }
    </style>
{% endblock %}


{% block right_content %}
    <div class="headline">
        <div style="width: 15%;height: 100%;line-height: 40px;float: left;padding-left: 1%;">
            <a href="#" style="color: #0b0b0b;">
                <i class="iconfont icon-faqi"></i>
                <a href="Javascript:;" style="color: #0b0b0b;">公务（外宾）接待清单审批</a>
            </a>
        </div>
        <div style="height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">
            <button id="add_station" type="button" style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;"
                    onclick="save_data()">
                保存
            </button>
        </div>

        <div style="width: 15%;height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">
            <button id="add_station" type="button" style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;" onclick="submit_data()">
                提交
            </button>
        </div>
    </div>
    <hr>

    <div style="width: 100%;height: 95%;overflow: auto;">
        <div id="menu_from"
             style="width: 100%;height: 100%;color: #2C3E50;display: inline-block;vertical-align: top;background: white;">
            <div style="width: 100%;height: 90%;display: inline-block;vertical-align: center;">

                <div style="width: 95%;margin-left: 2.5%;margin-top: 1%;height: 40px;padding-left: 0.5%;line-height: 40px;background: white;border: #cfcfcf solid 1px;text-align: center;">
                    <h3 id="form_name" style="letter-spacing: 8px;">公务（外宾）接待清单</h3>
                </div>
                <div style="width: 95%;margin-left: 2.5%;">
                    <table style="width: 100%;">
                        <tr style="width: 100%;">
                            <td colspan="4" style="width: 100%;height: 35px;background: #F5F5F5;padding-left: 0.5%;line-height: 40px;border-right: #cfcfcf solid 1px;border-left: #cfcfcf solid 1px;color: #00a0e9;">基本信息</td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 2.2px;">
                                <p style="width: 105px;float: right;text-align-last: justify;">承办人</p>
                            </td>
                            <td id="applicat" style="width: 35%;height: 35px;line-height: 35px;padding-left: 1%;border: #cfcfcf solid 0.5px;">{{ realname }}</td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                <p style="width: 105px;float: right;text-align-last: justify;">承办部门</p>
                            </td>
                            <td id="company" style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;">{{ department }}
                            </td>
                        </tr>
                        <tr style="width: 100%;">
                            <td colspan="4" style="width: 100%;height: 35px;background: #F5F5F5;padding-left: 0.5%;line-height: 40px;border-right: #cfcfcf solid 1px;border-left: #cfcfcf solid 1px;color: #00a0e9;">申请详情</td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                <p style="width: 105px;float: right;text-align-last: justify;">公务互动项目</p>
                            </td>
                            <td colspan="3" id="official_interaction" style="width: 85%;height: 35px;line-height: 35px;padding-left: 0.5%;border: #cfcfcf solid 0.5px;outline: none" contenteditable="true"></td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                <p style="width: 105px;float: right;text-align-last: justify;">陪餐人员</p>
                            </td>
                            <td id="conferee" onclick="model_line()" colspan="3" style="width: 85%;height: 35px;line-height: 35px;padding-left: 0.5%;border: #cfcfcf solid 0.5px;outline: none"></td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                <p style="width: 105px;float: right;text-align-last: justify;">接待时间</p>
                            </td>
                            <td id="reception_time" colspan="3" style="width: 35%;height: 35px;line-height: 35px;padding-left: 0.5%;border: #cfcfcf solid 0.5px;outline: none">
                                <input type="text" style="width: 70px;border-top: none;border-right: none;border-left: none;height: 25px;display: inline-block;" id="reception_year"> 年
                                <input type="text" style="width: 70px;border-top: none;border-right: none;border-left: none;height: 25px;display: inline-block;" id="reception_month"> 月
                                <input type="text" style="width: 70px;border-top: none;border-right: none;border-left: none;height: 25px;display: inline-block;" id="reception_day"> 日
                                <input type="checkbox" style="margin-left: 70px;" id="reception_morning"> 早
                                <input type="checkbox" style="margin-left: 8px;" id="reception_noon"> 中
                                <input type="checkbox" style="margin-left: 8px;" id="reception_night"> 晚
                            </td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                <p style="width: 105px;float: right;text-align-last: justify;">接待地点</p>
                            </td>
                            <td id="reception_location" colspan="3" style="width: 35%;height: 35px;line-height: 35px;padding-left: 0.5%;border: #cfcfcf solid 0.5px;outline: none" contenteditable="true"></td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                <p style="width: 105px;float: right;text-align-last: justify;">餐费支出</p>
                            </td>
                            <td id="meal_expenses" onblur="change_daxie(this.id)" style="width: 35%;height: 35px;line-height: 35px;padding-left: 0.5%;border: #cfcfcf solid 0.5px;outline: none" contenteditable="true"></td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                <p style="width: 105px;float: right;text-align-last: justify;">其他支出</p>
                            </td>
                            <td id="other_expenses" onblur="change_daxie(this.id)" style="width: 35%;height: 35px;line-height: 35px;padding-left: 0.5%;border: #cfcfcf solid 0.5px;outline: none" contenteditable="true"></td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                <p style="width: 105px;float: right;text-align-last: justify;">合计</p>
                            </td>
                            <td id="amount_to" style="width: 35%;height: 35px;line-height: 35px;padding-left: 0.5%;border: #cfcfcf solid 0.5px;outline: none"></td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                <p style="width: 105px;float: right;text-align-last: justify;">大写</p>
                            </td>
                            <td id="amount_big" style="width: 35%;height: 35px;line-height: 35px;padding-left: 0.5%;border: #cfcfcf solid 0.5px;outline: none"></td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 1.2px;">
                                <p style="width: 105px;float: right;text-align-last: justify;">备注</p>
                            </td>
                            <td id="note" colspan="3" style="width: 85%;height: 35px;line-height: 35px;padding-left: 1%;border: #cfcfcf solid 0.5px;outline: none" contenteditable="true"></td>
                        </tr>
                        <tr style="width: 100%;">
                            <td colspan="4" style="width: 100%;height: 35px;background: #F5F5F5;padding-left: 0.5%;line-height: 40px;border-right: #cfcfcf solid 1px;border-left: #cfcfcf solid 1px;color: #00a0e9;">接待对象 <p onclick="add_reception_objs()" style="float: right;color: #2db7f5;cursor: pointer;margin-right: 20px;">添加</p></td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;text-align: center;">
                                姓名
                            </td>
                            <td style="width: 35%;height: 35px;line-height: 35px;border: #cfcfcf solid 0.5px;outline: none;text-align: center;">单位</td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;text-align: center;">
                                职务
                            </td>
                            <td style="width: 35%;height: 35px;line-height: 35px;border: #cfcfcf solid 0.5px;outline: none;text-align: center;">
                                备注
                            </td>
                        </tr>
                    </table>
                    <table id="ObjectDetails" style="width: 100%;">
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;border-top: none;padding-left: 0.5%;" class="reception_name" contenteditable="true"></td>
                            <td style="width: 35%;height: 35px;line-height: 35px;border: #cfcfcf solid 0.5px;outline: none;border-top: none;padding-left: 0.5%;" class="reception_unit" contenteditable="true"></td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;border-top: none;padding-left: 0.5%;" class="reception_position" contenteditable="true"></td>
                            <td style="width: 35%;height: 35px;line-height: 35px;border: #cfcfcf solid 0.5px;outline: none;border-top: none;">
                                <input class="reception_node" type="text" style="width: 80%;height: 28px;border: none;outline: none;">
                            </td>
                        </tr>
                    </table>
                    <table style="width: 100%;">
                        <thead>
                            <tr style="width: 100%;">
                                <td colspan="6" style="width: 95%;margin-left: 2.5%;height: 40px;padding-left: 0.5%;line-height: 40px;background: #F5F5F5;border: #cfcfcf solid 1px;border-top: none;">
                                    上传附件
                                    <a href="javascript:;" class="file" style="vertical-align: top;margin-top: 5px;float: right;">
                                        上传文件
                                        <input type="file" name="party_main_body" id="party_main_body"
                                               onchange="upload_accessory('file1', 'party_main', 'party_main_body')">
                                    </a>
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 5%;border: #cccccc solid 1px;text-align: center;">序号</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                    文件名称
                                </td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                    文件大小
                                </td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                    上传时间
                                </td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                    上传人员
                                </td>
                                <td style="width: 15%;border: #cccccc solid 1px;border-left: none;text-align: center;">操作
                                </td>
                            </tr>
                        </thead>
                        <tbody style="overflow: auto;" id="party_main"></tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <div id="staff-select" class="shade">
        <div id="staff-model" style="width: 100%;height: 100%;position: absolute;">
            <div style="width: 900px;height: 500px;background: #F5F5F5;z-index: 10000;position: absolute;top: 50%;left: 50%;transform:translate(-50%,-50%);border-radius: 3px;border: #dfdfdf solid 1px;">
                <div id="staff-box" style="width: 100%;height: 40px;background: #f4f7fa;cursor: move;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom: #dfdfdf solid 1px;">
                    <div style="width: 20%;margin-left: 1%;display: inline-block;line-height: 40px;font-size: 14px;">
                        选择人员
                    </div>
                    <span onclick="close_model()" style="float: right;padding-right: 2%;cursor: pointer;line-height: 37px;">
                        <i class="iconfont icon-quchu"></i>
                    </span>
                </div>
                <div style="height: 460px;width: 100%;border-bottom: #dfdfdf solid 1px;">
                    <div style="width: 70px;height: 100%;border-right: #cfcfcf solid 1px;display: inline-block;vertical-align: top;">
                        <div id="dep" class="navigation navigation_color" onclick="change_navigation(this)">部门</div>
                        <div id="limits" class="navigation" onclick="change_navigation(this)">权限</div>
                        <div id="fun" class="navigation" onclick="change_navigation(this)">职能</div>
                    </div>
                    <div style="width: 200px;height: 100%;border-right: #cfcfcf solid 1px;display: inline-block;vertical-align: top;">
                        <div style="width: 100%;height: 50px;line-height: 50px;">
                            <input id="SearchDep" onkeydown="SearchDepartment()" class="search_input" type="text" placeholder="搜索" autocomplete="off" style="width: 95%;">
                        </div>
                        <div id="SecondaryNavigation" style="width: 100%;height: 403px;line-height: 50px;overflow: auto;"></div>
                    </div>
                    <div style="width: 200px;height: 100%;border-right: #cfcfcf solid 1px;display: inline-block;vertical-align: top;">
                        <div style="width: 100%;height: 50px;line-height: 50px;padding-left: 2%;">
                            <input type="checkbox" id="select-all" onclick="SelectAll(this)">
                            <input id="SearchPeo" onkeydown="SearchProple()" class="search_input" type="text" placeholder="搜索" autocomplete="off" style="width: 87%;">
                        </div>
                        <div id="ThreeNavigation" style="width: 100%;height: 403px;line-height: 50px;overflow: auto;"></div>
                    </div>
                    <div style="width: 410px;height: 100%;display: inline-block;vertical-align: top;overflow: auto">
                        <div style="width: 100%;height: 40px;text-align: left;font-size: 14px;line-height: 40px;">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;已选 <span id="selected-number">0</span> 人
                        </div>
                        <div id="selected-div" style="width: 100%;font-size: 14px;height: 370px;overflow: auto;line-height: 20px;">

                        </div>
                        <div style="width: 100%;font-size: 14px;height: 40px;text-align: center;">
                            <button onclick="IdentifyPersonnel()" style="width: 100px;height: 30px;line-height: 25px;text-align: center;letter-spacing: 5px;border-radius: 3px;border: #cfcfcf solid 1px;font-size: 14px;cursor: pointer;margin-top: 10px;">完成</button>
                            <button onclick="close_model()" style="margin-left: 15px;width: 100px;height: 30px;line-height: 25px;text-align: center;color: #0abb78;letter-spacing: 5px;border-radius: 3px;font-size: 14px;border: #cfcfcf solid 1px;cursor: pointer;margin-top: 10px;">取消</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block script %}
    <script type="text/javascript" src="../../static/public_file/other/jquery.js"></script>
    <script type="text/javascript" src="../../static/public_file/js/PersonnelChoosersNew.js" charset="gb2312"></script>
    <script type="text/javascript">
        window.onload = function () {
            document.getElementById("sponsor").className = "add_class";
            document.getElementById("personage").className = "add-nav-active";
        };

        const fj_number = '{{ uuid }}'

        function submit_data() {
            var form = new FormData();
            var official_interaction = document.getElementById('official_interaction').innerText;
            var accompanying_personnel = document.getElementById('conferee').innerText;
            var reception_year = document.getElementById('reception_year').value;
            var reception_month = document.getElementById('reception_month').value;
            var reception_day = document.getElementById('reception_day').value;
            var reception_morning = document.getElementById("reception_morning").checked;
            var reception_noon = document.getElementById("reception_noon").checked;
            var reception_night = document.getElementById("reception_night").checked;
            var reception_location = document.getElementById('reception_location').innerText;
            var meal_expenses = document.getElementById('meal_expenses').innerText;
            var other_expenses = document.getElementById('other_expenses').innerText;
            var amount_to = document.getElementById('amount_to').innerText;
            var amount_big = document.getElementById('amount_big').innerText;
            var note = document.getElementById('note').innerText;
            var reception_name_list = document.getElementsByClassName("reception_name");
            var reception_unit_list = document.getElementsByClassName("reception_unit");
            var reception_position_list = document.getElementsByClassName("reception_position");
            var reception_node_list = document.getElementsByClassName("reception_node");
            if (!official_interaction) {
                alert('公务互动项目不能为空！')
                return false
            }
            if (!accompanying_personnel) {
                alert('陪餐人员不能为空！')
                return false
            }
            if (!reception_year || !reception_month || !reception_day) {
                alert('请将接待时间填写完整！')
                return false
            }
            if (!reception_morning && !reception_noon && !reception_night) {
                alert('请将接待时间填写完整！')
                return false
            }
            if (!reception_location) {
                alert('接待地点不能为空！')
                return false
            }
            document.getElementById("loading").style.display = "inline-block";
            var reception_time = {"reception_year": reception_year, "reception_month": reception_month, "reception_day": reception_day,
            "reception_morning": String(reception_morning), "reception_noon": String(reception_noon), "reception_night": String(reception_night)};

            var reception_recipients = [];
            for (var jj=0; jj<reception_name_list.length; jj++) {
                reception_recipients.push({"reception_name": reception_name_list[jj].innerText, "reception_unit": reception_unit_list[jj].innerText,
                "reception_position": reception_position_list[jj].innerText, "reception_node": reception_node_list[jj].value})
            }

            form.append("official_interaction", official_interaction);
            form.append('accompanying_personnel', accompanying_personnel)
            form.append('reception_time', JSON.stringify(reception_time))
            form.append('reception_location', reception_location)
            form.append('meal_expenses', meal_expenses)
            form.append('other_expenses', other_expenses)
            form.append('amount_to', amount_to)
            form.append('amount_big', amount_big)
            form.append('note', note)
            form.append('reception_recipients', JSON.stringify(reception_recipients))
            form.append('fj_number', fj_number)
            var xhr = new XMLHttpRequest();
            xhr.open('post', "/new-flow-logic/reception_checklist_index.html", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert("创建成功");
                            window.location = "/new-flow-logic/reception_checklist_list.html";
                        } else {
                            alert(JsonDate['message']);
                            document.getElementById("loading").style.display = "none";
                        }
                    }
                }
             };
        }

        function save_data() {
            var form = new FormData();
            var official_interaction = document.getElementById('official_interaction').innerText;
            var accompanying_personnel = document.getElementById('conferee').innerText;
            var reception_year = document.getElementById('reception_year').value;
            var reception_month = document.getElementById('reception_month').value;
            var reception_day = document.getElementById('reception_day').value;
            var reception_morning = document.getElementById("reception_morning").checked;
            var reception_noon = document.getElementById("reception_noon").checked;
            var reception_night = document.getElementById("reception_night").checked;
            var reception_location = document.getElementById('reception_location').innerText;
            var meal_expenses = document.getElementById('meal_expenses').innerText;
            var other_expenses = document.getElementById('other_expenses').innerText;
            var amount_to = document.getElementById('amount_to').innerText;
            var amount_big = document.getElementById('amount_big').innerText;
            var note = document.getElementById('note').innerText;
            var reception_name_list = document.getElementsByClassName("reception_name");
            var reception_unit_list = document.getElementsByClassName("reception_unit");
            var reception_position_list = document.getElementsByClassName("reception_position");
            var reception_node_list = document.getElementsByClassName("reception_node");

            document.getElementById("loading").style.display = "inline-block";
            var reception_time = {"reception_year": reception_year, "reception_month": reception_month, "reception_day": reception_day,
            "reception_morning": String(reception_morning), "reception_noon": String(reception_noon), "reception_night": String(reception_night)};

            var reception_recipients = [];
            for (var jj=0; jj<reception_name_list.length; jj++) {
                reception_recipients.push({"reception_name": reception_name_list[jj].innerText, "reception_unit": reception_unit_list[jj].innerText,
                "reception_position": reception_position_list[jj].innerText, "reception_node": reception_node_list[jj].value})
            }

            form.append("official_interaction", official_interaction);
            form.append('accompanying_personnel', accompanying_personnel)
            form.append('reception_time', JSON.stringify(reception_time))
            form.append('reception_location', reception_location)
            form.append('meal_expenses', meal_expenses)
            form.append('other_expenses', other_expenses)
            form.append('amount_to', amount_to)
            form.append('amount_big', amount_big)
            form.append('note', note)
            form.append('reception_recipients', JSON.stringify(reception_recipients))
            form.append('fj_number', fj_number)
            var xhr = new XMLHttpRequest();
            xhr.open('post', "/new-flow-logic/reception_checklist_draft.html", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert("保存成功！");
                            window.location = "/new-flow-logic/reception_checklist_list.html";
                        } else {
                            alert(JsonDate['message']);
                            document.getElementById("loading").style.display = "none";
                        }
                    }
                }
             };
        }

        // 上传附件
        function upload_accessory(file_type, tbody_id, accessory_type) {
            document.getElementById("loading").style.display = "inline-block";
            var form = new FormData();
            var files = document.getElementById(accessory_type).files[0];
            form.append(file_type, files);
            form.append('number', fj_number)
            form.append('source', 'jdqd')
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/topics_attachments_upload", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        creat_table(JsonDate, tbody_id)
                    }
                }
            };
        }

        // 创建附件列表
        function creat_table(JsonData, tbody_id) {
            var t_table = document.getElementById(tbody_id);
            var local_host = window.location.host;
            if (Array.isArray(JsonData["pdf_path"])) {
                for (var i = 0; i < JsonData["pdf_path"].length; i++) {
                    var tr = document.createElement("tr");var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");var td5 = document.createElement("td");var td6 = document.createElement("td");
                    td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                    td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                    td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                    td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                    td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                    td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"][i]["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["pdf_path"][i]["id"] + "\")'>删除</a>";
                    td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);
                    t_table.appendChild(tr);
                }
                if (JsonData["pdf_path"].length > 1) {
                    document.getElementById("del_adjunct").style.display = 'block';
                }
            } else {
                tr = document.createElement("tr");td1 = document.createElement("td");td2 = document.createElement("td");td3 = document.createElement("td");td4 = document.createElement("td");td5 = document.createElement("td");td6 = document.createElement("td");
                td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["id"] + "\")'>删除</a>";
                td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);t_table.appendChild(tr);
            }
        }

        function RemoveTr(_this, tbody_id, wj_id) {
            var table = document.getElementById(tbody_id);
            var trNode = $(_this).parent().parent();
            trNode.remove();

            for (var i=0; i<table.children.length; i++){
                table.children[i].children[0].innerHTML=i+1;
            }

            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/delete_attachments_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("id="+String(wj_id));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        alert("删除成功！")
                    }
                }
            };
        }

        function delete_tr_fun(this_tag) {
            var trNode = $(this_tag).parent().parent();
            trNode.remove();
        }

        function add_reception_objs() {
            var add_html = `
                <tr style="margin-left: 1%;">
                    <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;border-top: none;padding-left: 0.5%;" class="reception_name" contenteditable="true"></td>
                    <td style="width: 35%;height: 35px;line-height: 35px;border: #cfcfcf solid 0.5px;outline: none;border-top: none;padding-left: 0.5%;" class="reception_unit" contenteditable="true"></td>
                    <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;border-top: none;padding-left: 0.5%;" class="reception_position" contenteditable="true"></td>
                    <td style="width: 35%;height: 35px;line-height: 35px;border: #cfcfcf solid 0.5px;outline: none;border-top: none;">
                        <input class="reception_node" type="text" style="width: 80%;height: 28px;border: none;outline: none;">
                        <p onclick="delete_tr_fun(this)" style="float: right;color: red;cursor: pointer;margin-right: 20px;">删除</p>
                    </td>
                </tr>
            `
            $("#ObjectDetails").append(add_html);
        }

        function IdentifyPersonnel() {
            var prople_list = [];
            var selected_personnel_list = document.getElementsByClassName('selected-personnel');
            for (var i=0; i<selected_personnel_list.length; i++) {
                prople_list.push(selected_personnel_list[i].innerText)
            }
            document.getElementById("conferee").innerText = prople_list.join();
            close_model()
        }

        function change_daxie(_this) {
            var meal_expenses = document.getElementById("meal_expenses").innerText.replace(',', '').replace(',', '').replace(',', '').replace(',', '').replace(',', '')
            var other_expenses = document.getElementById("other_expenses").innerText.replace(',', '').replace(',', '').replace(',', '').replace(',', '').replace(',', '')
            if (meal_expenses && other_expenses) {
                var amount_to = parseFloat(meal_expenses) + parseFloat(other_expenses)
            }else if (!meal_expenses && !other_expenses) {
                amount_to = 0
            }else if (meal_expenses && !other_expenses) {
                amount_to = meal_expenses
            }else {
                amount_to = other_expenses
            }
            document.getElementById("amount_to").innerText = formatMonenyNumber(amount_to)
            document.getElementById("amount_big").innerText=ToString(document.getElementById("amount_to").innerText.replace(',', '').replace(',', '').replace(',', '').replace(',', '').replace(',', ''));
            document.getElementById(_this).innerText = formatMonenyNumber(document.getElementById(_this).innerText.replace(',', '').replace(',', '').replace(',', '').replace(',', '').replace(',', ''));
        }

        function formatMonenyNumber(number, toFixed = 2) {
            let str = [];
            if (!number) return 0
            if (typeof number === "number") number = String(number)
            let tempNumber = number.split('.');
            number = tempNumber[0]
            if (number.length <= 3) {
                if (tempNumber[1]) {
                    var decimils = tempNumber[1].slice(0, toFixed);
                if (decimils.length === 1){
                    decimils = decimils + "0";
                }
                number += '.' + decimils;
                }else {
                    number += '.00'
                }
                return number
            }
            number.split('').reverse().forEach((item, index) => {
                if (index !== 0 && index % 3 === 0) {
                    str.push(',', item)
                } else {
                    str.push(item)
                }
            })
            number = str.reverse().join('')
            if (tempNumber[1]) {
                var decimils = tempNumber[1].slice(0, toFixed);
                if (decimils.length === 1){
                    decimils = decimils + "0";
                }
                number += '.' + decimils;
            }else {
                 number += '.00'
            }
            return number;
        }

        function ToString(money) {
            console.log(money, '执行了吗');
            //汉字的数字
            var cnNums = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
            //基本单位
            var cnIntRadice =['', '拾', '佰', '仟'];
            //对应整数部分扩展单位
            var cnIntUnits = ['', '万', '亿', '兆'];
            //对应小数部分单位
            var cnDecUnits = ['角', '分', '毫', '厘'];
            //整数金额时后面跟的字符
            var cnInteger = '整';
            //整型完以后的单位
            // var cnIntLast = '圆';
            var cnIntLast = '元';
            //最大处理的数字
            var maxNum = 999999999999999.9999;
            //金额整数部分
            var integerNum;
            //金额小数部分
            var decimalNum;
            //输出的中文金额字符串
            var chineseStr = '';
            //分离金额后用的数组，预定义
            var parts;
            if (money === '') { return ''; }
            money = parseFloat(money);
            if (money >= maxNum) {
                //超出最大处理数字
                return '';
            }
            if (money === 0) {
                chineseStr = cnNums[0] + cnIntLast + cnInteger;

                return chineseStr;
            }

            //转换为字符串
            money = money.toString();

            if (money.indexOf('.') === -1) {
                integerNum = money;
                decimalNum = '';
            } else {
                parts = money.split('.');
                integerNum = parts[0];

                decimalNum = parts[1].substring(0, 2);
            }
            //获取整型部分转换
            if (parseInt(integerNum, 10) > 0) {
                var zeroCount = 0;
                var IntLen = integerNum.length;
                for (var i = 0; i < IntLen; i++) {
                    // var n = integerNum.substr(i, 1);
                    var n = integerNum.substring(i, i+1);
                    var p = IntLen - i - 1;
                    var q = p / 4;
                    var m = p % 4;
                    if (n === '0') {
                        zeroCount++;
                    } else {
                        if (zeroCount > 0) {
                            chineseStr += cnNums[0];
                        }
                        //归零
                        zeroCount = 0;
                        chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
                    }
                    if (m === 0 && zeroCount < 4) {
                        chineseStr += cnIntUnits[q];
                    }
                }
                chineseStr += cnIntLast;
            }
            //小数部分
            if (decimalNum !== '') {
                var decLen = decimalNum.length;
                for (var i = 0; i < decLen; i++) {
                    // var n = decimalNum.substr(i, 1);
                    var n = decimalNum.substring(i, i+1);
                    if (n !== '0') {
                        // chineseStr += cnNums[Number(n)] + cnDecUnits[i];
                        chineseStr += cnNums[parseInt(n)] + cnDecUnits[i];
                    }
                }
            }
            if (chineseStr === '') {
                chineseStr += cnNums[0] + cnIntLast + cnInteger;
            } else if (decimalNum === '') {
                chineseStr += cnInteger;
            }

            return chineseStr;
        }
    </script>
{% endblock %}



